package cn.jsj.cxsys.dao.dynamicSQL;

import org.apache.ibatis.jdbc.SQL;

public class DynamicSQLFactory {
    public String RecordsScreen(String studentAccount, String teacherAccount, String startTime, String overTime, int labID, String labNum, int pcID){
        return new SQL(){
            {
                SELECT("*");
                FROM("vi_record");
                if(1 == 1){
                    WHERE("1=1");
                    if(studentAccount!=null && studentAccount.trim().length()>4){
                        WHERE("user_id=(select user_id from tb_user where account=#{studentAccount})");
                    }
                    if(teacherAccount != null && teacherAccount.trim().length()>4){
                        WHERE("tele_number_lader=(select tele_number from tb_user where account=#{teacherAccount})");
                    }
                    if(startTime!=null && startTime.trim().length()>1){
                        WHERE("in_time>#{startTime}");
                    }
                    if(overTime!=null && overTime.trim().length()>1){
                        WHERE("out_time<#{overTime}");
                    }
                    if(labID > 0){
                        WHERE("lab_id=#{labID}");
                    }
                    if(labNum!=null && labNum.trim().length()>1){
                        WHERE("lab_id=(select lab_id from tb_lab where lab_num=#{labNum})");
                    }
                    if(pcID>0)
                        WHERE("pc_num=#{select pc_num from tb_pc where pc_id=#{pcID}}");
                    }

                }

        }.toString();
    }

    public String UsersScreen(int userID, String account, String className, String name, String teleNumber){
        return new SQL(){
            {
                SELECT("*");
                FROM("vi_user");
                if(1 == 1){
                    WHERE("1=1");
                    if(userID >0){
                        WHERE("user_id=#{userID}");
                    }
                    if(account!=null && account.trim().length()>0){
                        WHERE("account=#{account}");
                    }
                    if(className!=null && className.trim().length()>0){
                        WHERE("class_name=#{className}");
                    }
                    if(name!=null){
                        WHERE("name=#{name}");
                    }
                    if(teleNumber != null && teleNumber.length()==11){
                        WHERE("tele_number=#{teleNumber}");
                    }
                }
            }
        }.toString();
    }
}
